<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>添加商品</title>
	    <link rel="stylesheet" href="css/AllStyle.css" />
	    <link rel="stylesheet" href="css/iconfont.css" />
	    <script type="text/javascript" src="js/common.js" ></script>
	    <script type="text/javascript" src="js/companydata.js" ></script>
	    <script type="text/javascript" src="js/data.js" ></script>
	    <script type="text/javascript" src="js/tmpl.js" ></script>
	</head>
	<body>
		<!-- 页头 -->
	    <section>
		    <script type="text/javascript">
		        AllPageHeader()
		    </script>
	    </section>
	    
	    <!-- 页面  -->
	    <section class="AllContent">
	    	<form>
	    		<div class="FormStyle">
	    			<ul>
	    				<li>图片标题：</li>
						<li><input type="text" id="title" name="title" value="" placeholder="图片标题"></li>
						
						<li>图片链接：</li>
						<li><input type="text" id="url" name="url" value="" placeholder="http://www.zdma.cn"></select></li>
						
						<li>图片分组：</li>
						<li>
							<select name="groupname" id="groupname">
                                <option value="默认分组">默认分组</option>
                                <option value="产品图片">产品图片</option>
                                <option value="广告图片">广告图片</option>
                                <option value="其它">其它</option>
                            </select>
						</li>
	    			</ul>
	    			<div class="FormPhoto">
	    				<img id="pic_url" name="pic_url" src="images/Photo2.png">
	    				<input type="file" id="file_upload"/>
	    			</div>
	    			<p style="margin:0px 4.5%;font-size:0.83em;color:#999;margin-top:10px;font-family: arial;line-height:23px;">上传图片大小不能超过2M，最佳尺寸为200x200px</p>
	    			
	    			<input type="file" class="form-control" id="file" name="file" style="display:none" onchange="$('#pic_url').val(this.value); ajaxFileUpload();" />                
                    <input type="text" id="pid" name="id" value=""  style="display:none"/>
	    			
	    			<button class="NextButton" type="button" onclick="savepic();">保存</button>
	    		</div>
	    	</form>
	    	
	    	<div class="SlidingLayer">
	    		<div style="overflow: hidden;background-color:#fff;">
	    			<span class="ImageHostingTitle">空间图片</span>
	    			<img class="CloseImg" style="width:30px;" src="images/remover.png">
	    		</div>
	    		<ul id="piclist">
	    			
	    		</ul>
	    	</div>
	    </section>
	    
	    <section>
	    	<div class="MaskLayer">
		    	<div class="MaskContent">
		    		<p><img src="images/loading5.gif"></p>
		    		<p>正在添加...</p>
		    	</div>
	    	</div>
	    </section>
		
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jsAddress.js" ></script>
	<script type="text/javascript">
		$('.AllHeader li:eq(1)').text('图片编辑')
	    
	    $(function () {
	        var pid = $_GET['id'];
	        
	        $("#file_upload").change(function() {
				var $file = $(this);
				var fileObj = $file[0];
				var windowURL = window.URL || window.webkitURL;
				var dataURL;
				var $img = $("#pic_url");
				 
				if(fileObj && fileObj.files && fileObj.files[0]){
				dataURL = windowURL.createObjectURL(fileObj.files[0]);
				$img.attr('src',dataURL);
				}else{
				dataURL = $file.val();
				var imgObj = document.getElementById("pic_url");
				imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
				 
				}
			});
	        
	        $.ajax({
	            type: "post",
	            url: getServerUrl() + "/Open/Company/picitem",
	            dataType: 'json',
	            data: 'access_token=' + getToken()+'&id='+pid,
	            success: function (json) {
	                $("#pid").val(json.id);
	                $("#title").val(json.title);
	                $("#url").val(json.url);
	                $("#groupname").val(json.groupname);
	                $("#logoimg").attr("src",json.image);
					$('#pic_url').attr("src",json.image);
	            },
	            error: function () {
	                alertMessage("请检查网络连接！");
	            }
	        });
	    });
	
	    function onDeviceReady() {
	        //document.addEventListener("backbutton", onBackKeyDown, false);
	    }
	    function onBackKeyDown() {
	        //openUrl("/Desktop/index");
	    }
	
	    function savepic() {
	        var id = $("#pid").val();
	        var title = $("#title").val();
	        var url = $("#url").val();
	        var groupname = $("#groupname").val();
	
	        if (empty(id)) {
	            alertMessage("产品id不能为空！");
	            return;
	        }
	        if (empty(title)) {
	            alertMessage("产品名称不能为空！");
	            return;
	        }
	        var datas = {access_token:getToken(),id:id,title:title,url:url,groupname:groupname};
	        $.ajax({
	            type: "post",
	            url: getServerUrl() + "/Open/Company/editpic",
	            dataType: 'json',
	            data: datas,
	            success: function (json) {
	                if (json.result == "1") {
	                    openUrl("picasa.html");
	                } else {
	                    alertMessage("编辑产品失败:[" + json.error_description + "]");
	                }
	            }
	        });
	    }
	
	    function ajaxFileUpload()
	    {
	        $("#loading")
	                .ajaxStart(function () {
	                    $(this).show();
	                })
	                .ajaxComplete(function () {
	                    $(this).hide();
	                });
	        var groupname = $("#groupname").val();
	        $.ajaxFileUpload
	                (
	                        {
	                            url: '/Open/Common/uploadpic',
	                            secureuri: false,
	                            fileElementId: 'file',
	                            dataType: 'json',
	                            data: {access_token:getToken(),ajax: '1', groupname: groupname, updFileName: 'file'},
	                            success: function (data)
	                            {
	                                //alert(data);
	                                if (data.data) {
	                                    //$('#logoimg').attr('src','/Public/upload/pics/'+data.data);
	                                    //$('#pic').val('/Public/upload/pics/'+data.data);
	                                    $('#logoimg').attr('src', data.data);
	                                    $('#pic_url').val(data.data);
	                                }
	                                //alert(data.data);
	                            },
	                            error: function (data, status, e)
	                            {
	                                //alert(data);
	                            }
	                        }
	                )
	
	        return false;
	    }
	</script>
</html>